import numpy as np


def count_assignment(self, pop):
    assigns = np.zeros(shape=(self.m, self.n + 1), dtype=int)  # [m][n]: salesman m is assigned with city n
    for s in pop:
        for k, tour in enumerate(s.tours):
            for city in tour:
                if city != self.depot:
                    assigns[k][city] += 1  # the number of individuals that assign city to k
    return assigns


def assignment_entropy(self, pop):
    assigns = self.count_assignment(pop)
    assigns = assigns / self.NP * np.log(assigns / self.NP + 1e-5)
    return -np.sum(assigns)
